<template>
  <div>
    <div class="ser_div">
      <el-row>
        <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 订单号 </el-col>
            <el-col :span="16">
              <el-input v-model="ser.order_number" type="number"></el-input>
            </el-col>
          </el-row>
        </el-col>
        <!-- <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 流水号 </el-col>
            <el-col :span="16">
              <el-input v-model="ser.serial_number"></el-input>
            </el-col>
          </el-row>
        </el-col> -->
        <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 客户 </el-col>
            <el-col :span="16">
              <el-select filterable v-model="ser.customer_id" placeholder="请选择客户" style="width: 100%">
                <el-option v-for="(item, index) in CustomerList" :key="index" :label="item.customer_name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-col>
          </el-row>
        </el-col>
        <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 产品 </el-col>
            <el-col :span="16">
              <el-select filterable v-model="ser.product_id" @change="product_id_change" placeholder="请选择产品"
                style="width: 100%">
                <el-option v-for="(item, index) in productList" :key="index" :label="item.product_name" :value="item.id">
                </el-option>
              </el-select>
            </el-col>
          </el-row>
        </el-col>
        <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 型号 </el-col>
            <el-col :span="16">
              <el-select filterable v-model="ser.model_number_id" placeholder="请选择型号" style="width: 100%">
                <el-option v-for="(item, index) in ModelNumberList" :key="index" :label="item.model_number"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-col>
          </el-row>
        </el-col>
        <!-- <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 是否已收余款 </el-col>
            <el-col :span="16">
              <el-select
                filterable
                v-model="ser.is_residual_payment"
                style="width:60%"
              >
                <el-option
                  label="是"
                  :value="1"
                >
                </el-option>
                <el-option
                  label="否"
                  :value="2"
                >
                </el-option>
              </el-select>
            </el-col>
          </el-row>
        </el-col> -->
        <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 状态 </el-col>
            <el-col :span="16">
              <el-select v-model="ser.logistics_status" placeholder="请选择物流状态" style="width: 100%">
                <el-option v-for="(item, index) in logistics_statuslist" :key="index" :label="item.lable"
                  :value="item.status">
                </el-option>
              </el-select>
            </el-col>
          </el-row>
        </el-col>
        <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 订单日期范围 </el-col>
            <el-col :span="16">
              <el-date-picker v-model="order_data" @change="order_data_change" value-format="yyyy-MM-dd" type="daterange"
                range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
              </el-date-picker>
            </el-col>
          </el-row>
        </el-col>
        <el-col>
          <el-button @click="search(0)" class="add_btn">查询</el-button>
          <el-button @click="searchreset" class="add_btn">重置</el-button>
          <el-button @click="search(2)" class="add_btn">导出</el-button>
          <el-button type="primary" @click="print()" class="add_btn">打印出货单</el-button>
          <!-- <el-button type="primary" @click="prints()" class="add_btn"
            >打印标签</el-button
          > -->
          <el-button type="primary" @click="push_daifahuo()" class="add_btn">设置为待发货</el-button>
        </el-col>
      </el-row>
    </div>

    <el-table :data="dataList" stripe v-loading="loading" style="width: 100%" @selection-change="handleSelectionChange"
      border>
      <el-table-column type="selection"> </el-table-column>

      <el-table-column prop="id" label="ID" width="60"> </el-table-column>
      <el-table-column prop="order_id" label="订单ID" width="60"> </el-table-column>

      <el-table-column prop="warehouse_entry_time" label="入库日期" width="100">
      </el-table-column>
      <el-table-column label="客户名称" width="80">
        <template slot-scope="scope">
          {{
            scope.row.order.customer ? scope.row.order.customer.customer_name : ""
          }}
        </template>
      </el-table-column>
      <el-table-column label="订单号" width="70">
        <template slot-scope="scope">
          {{ scope.row.order.order_number }}
        </template>
      </el-table-column>
      <!-- <el-table-column label="流水号" width="70">
        <template slot-scope="scope">
          {{ scope.row.order.serial_number }}
        </template>
      </el-table-column> -->
      <el-table-column label="产品名称" width="80">
        <template slot-scope="scope">
          {{ scope.row.order.product_name ? scope.row.order.product_name.product_name : '' }}
        </template>
      </el-table-column>
      <el-table-column label="产品型号" width="80">
        <template slot-scope="scope">
          {{ scope.row.order.model_number_name ? scope.row.order.model_number_name.model_number : "" }}
        </template>
      </el-table-column>
      <!-- <el-table-column label="方向" width="60">
        <template slot-scope="scope">
          {{ scope.row.direction }}
        </template>
      </el-table-column> -->
      <el-table-column label="规格" width="70">
        <template slot-scope="scope">
          {{
            scope.row.order.specification
            ? scope.row.order.specification.specification
            : ""
          }}
        </template>
      </el-table-column>
      <el-table-column label="颜色" width="70">
        <template slot-scope="scope">
          {{ scope.row.order.color ? scope.row.order.color.color : "" }}
        </template>
      </el-table-column>
    
      <el-table-column prop="logistics_status" label="发货状态" width="120">
        <template slot-scope="scope">
          <span v-if="scope.row.logistics_status == 1" style="color: #dd8211">待发货</span>
          <span v-if="scope.row.logistics_status == 2" style="color: #f1420d">未发货</span>
          <span v-if="scope.row.logistics_status == 4" style="color: #b47425">部分待发货</span>
          <span v-if="scope.row.logistics_status == 5" style="color: #b47425">部分未发货</span>
          <span v-if="scope.row.logistics_status == 3" style="color: #0ca747">已发货</span>
        </template>
      </el-table-column>
      <el-table-column prop="remark" label="备注" width="300">
        <template slot-scope="scope">
          <span style="display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 3;overflow: hidden;">{{scope.row.order.remark}}</span>
        </template>
      </el-table-column>
      <el-table-column label="发货时间" width="120">
        <template slot-scope="scope">
          {{ scope.row.delivery_time }}
        </template>
      </el-table-column>
      <el-table-column label="物流信息" width="120">
        <template slot-scope="scope">
          {{ scope.row.logistics_info }}
        </template>
      </el-table-column>
      <el-table-column label="件数" width="70">
        <template slot-scope="scope">
          {{ scope.row.num }}
          <!-- <div @dblclick="dbclick_input(scope.row.id)">
            <el-input
              v-model="scope.row.num"
              @blur="push_num_jianshu(scope.row.id, scope.row.num)"
              :disabled="disableds['disableds_' + scope.row.id]"
            ></el-input>
          </div> -->
        </template>
      </el-table-column>
      <el-table-column prop="receivables" label="金额" width="80">
        <template slot-scope="scope">
          {{ scope.row.order.receivables }}
        </template>
      </el-table-column>
      <!-- <el-table-column prop="received" label="定金" width="120">
        <template slot-scope="scope">
          {{ scope.row.order.received }}
        </template>
      </el-table-column>
      <el-table-column label="折扣" width="120">
        <template slot-scope="scope">
          {{ scope.row.models_field ? scope.row.models_field.discount + '%' : '' }}
        </template>
      </el-table-column>
      <el-table-column label="余款" width="120">
        <template slot-scope="scope">
          {{ scope.row.models_field ? scope.row.models_field.residual_payment : '' }}
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="是否已收余款" width="90">
        <template slot-scope="scope">
          <span v-if="scope.row.models_field.is_residual_payment.key == 1">是</span>
          <span v-if="scope.row.models_field.is_residual_payment.key == 2">否</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="已发件数" width="120">
        <template slot-scope="scope">
          {{ scope.row.sent_num }}
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="待发件数" width="80">
        <template slot-scope="scope">
          {{ scope.row.to_be_sent_num }}
        </template>
      </el-table-column> -->
      <el-table-column label="仓库" width="120">
        <template slot-scope="scope">
          {{ scope.row.warehouse ? scope.row.warehouse.warehouse_name : '' }}
        </template>
      </el-table-column>
    
      <el-table-column label="操作" width="90" fixed="right">
        <template slot-scope="scope">
          <el-dropdown trigger="click">
            <el-button type="primary" size="small">
              操作<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <!-- <el-dropdown-item>
                <el-popconfirm
                  v-if="
                    scope.row.is_deduct_money == 2 ||
                    scope.row.is_deduct_money == null
                  "
                  confirm-button-text="好的"
                  cancel-button-text="不用了"
                  icon-color="red"
                  title="确定将此产品进行扣款吗？"
                  @confirm="koukuan(scope.row.id, 1)"
                >
                  <el-button slot="reference" type="text"> 扣款</el-button>
                </el-popconfirm>
              </el-dropdown-item> 

            <el-dropdown-item>
                <el-popconfirm
                  v-if="scope.row.is_deduct_money == 1"
                  confirm-button-text="好的"
                  cancel-button-text="不用了"
                  icon-color="red"
                  title="确定将此扣款进行取消吗？"
                  @confirm="koukuan(scope.row.id, 2)"
                >
                  <el-button slot="reference" type="text"> 取消扣款</el-button>
                </el-popconfirm>
              </el-dropdown-item> -->
              <!-- <el-dropdown-item>
                <el-popconfirm v-if="scope.row.models_field.is_residual_payment.key == 2" confirm-button-text="好的"
                  cancel-button-text="不用了" icon-color="red" title="确定将此订单设为已收余额？"
                  @confirm="set_yishou(scope.row.order_id)">
                  <el-button slot="reference" type="text"> 已收余款</el-button>
                </el-popconfirm>
              </el-dropdown-item> -->
              <el-dropdown-item>
                <el-button @click="diaohuo(scope.row)" type="text"
                  :disabled="scope.row.logistics_status != 2">调货</el-button>
              </el-dropdown-item>
              <el-dropdown-item>
                <el-button style="padding-left: 8px" @click="diaohuojilu(scope.row)"
                  :disabled="scope.row.stock_allocation_log.length == 0" type="text">调货记录</el-button>
              </el-dropdown-item>
              <el-dropdown-item>
                <el-button type="text" style="padding-left: 8px; padding-right: 8px"
                  :disabled="scope.row.logistics_status == 1 || scope.row.logistics_status == 3"
                  @click="push_daifahuos(scope.row)">设置为待发货</el-button>
              </el-dropdown-item>
              <el-dropdown-item>
                <el-popconfirm confirm-button-text="好的" cancel-button-text="不用了" icon-color="red" title="是否撤销待发货状态？"
                  @confirm="push_daifahuos_false(scope.row)">
                  <el-button slot="reference" :disabled="scope.row.logistics_status == 2 ||
                    scope.row.logistics_status == 3 ||
                    scope.row.logistics_status == 5
                    " type="text">
                    取消待发货</el-button>
                </el-popconfirm>
              </el-dropdown-item>
              <el-dropdown-item>
                <el-popconfirm confirm-button-text="好的" cancel-button-text="不用了" icon-color="red" title="确定将此产品转到备货库吗？"
                  @confirm="beihuo(scope.row)">
                  <el-button slot="reference" :disabled="scope.row.logistics_status == 3" type="text">
                    转到备货库</el-button>
                </el-popconfirm>
              </el-dropdown-item>
              <el-dropdown-item>
                <el-button type="text" @click="set_kehu(scope.row)">修改客户</el-button>
              </el-dropdown-item>
              <el-dropdown-item>
                <el-button type="text" @click="
                  chengpin_shanchu(scope.row.id, scope.row.order.order_number)
                  ">删除</el-button>
              </el-dropdown-item>
              <el-dropdown-item>
                <el-button type="text" @click="set_cangku(scope.row)">修改仓库</el-button>
              </el-dropdown-item>


            </el-dropdown-menu>
          </el-dropdown>
          <!-- <div
            style="
              display: grid;
              grid-template-rows: 1fr 1fr;
              grid-template-columns: 1fr 1fr 1fr;
              grid-gap: 10px;
              justify-items: center;
              align-items: center;
            "
          >
          </div> -->
        </template>
      </el-table-column>
    </el-table>

    <div class="pagination">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" background @prev-click="prev"
        @next-click="next" :current-page.sync="pagination.page" :page-size="pagination.per_page"
        layout="sizes,total, prev, pager, next" :total="total">
      </el-pagination>
    </div>

    <el-dialog title="调货" :visible.sync="ishuojia" width="60%" :close-on-click-modal="false" @close="close_dialog">
      <div>
        <el-table :data="diaoList" stripe style="width: 100%" border>
          <el-table-column prop="delivery_date" label="交货日期" width="180">
          </el-table-column>
          <el-table-column label="客户名称" width="120">
            <template slot-scope="scope">
              {{ scope.row.customer ? scope.row.customer.customer_name : "" }}
            </template>
          </el-table-column>
          <el-table-column label="订单号" width="150">
            <template slot-scope="scope">
              {{ scope.row.order_number }}
            </template>
          </el-table-column>
          <el-table-column prop="remark" label="备注" width="300">
            <template slot-scope="scope">
              <span
                style="display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 3;overflow: hidden;">{{ scope.row.remark }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="100" fixed="right">
            <template slot-scope="scope">
              <el-popconfirm confirm-button-text="好的" cancel-button-text="不用了" icon="el-icon-sort" icon-color="red"
                title="确定对此产品进行调货吗？" @confirm="add_product(scope.row)">
                <el-button slot="reference" type="text" icon="el-icon-sort">
                  调货</el-button>
              </el-popconfirm>
            </template>
          </el-table-column>
        </el-table>

        <div class="pagination">
          <el-pagination @size-change="handleSizeChange_diao" @current-change="handleCurrentChange_diao" background
            @prev-click="prev_diao" @next-click="next_diao" :current-page.sync="pagination_diao.page"
            :page-sizes="[10, 20, 30, 40, 50, 60, 70, 80, 90, 100]" :page-size="pagination_diao.per_page"
            layout="total, prev, pager, next" :total="total_diao">
          </el-pagination>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="ishuojia = false" type="primary" size="small">取 消</el-button>
      </span>
    </el-dialog>

    <el-dialog title="调货信息" :visible.sync="isjilu" width="40%" @close="close_dialog">
      <div v-for="item in diaohuojilulist" :key="item.id">
        当前订单原客户
        <span style="font-weight: bold">{{
          item.order.customer.customer_name
        }}</span>
        在 {{ item.created_at }}与
        <span style="font-weight: bold">{{
          item.finish_order.customer.customer_name
        }}</span>的订单({{ item.order.order_number }})进行了调货
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="isjilu = false">取 消</el-button>
      </span>
    </el-dialog>
    <el-dialog title="设置待发货" :visible.sync="isdfh" width="30%" @close="close_dialog_2">
      <div>
        <el-row style="display: flex; align-items: center">
          <el-col :span="2"> 件数 </el-col>
          <el-col :span="20">
            <el-input-number v-model="fahuo_num" @change="handleChange" :min="0" :max="maxnum" label="请输入件数"
              style="width: 100%; text-align: left"></el-input-number>
          </el-col>
        </el-row>
        <el-row style="margin-top: 15px; display: flex; align-items: center">
          <el-col :span="2"> 备注 </el-col>
          <el-col :span="20">
            <el-input placeholder="请输入备注" v-model="remark"></el-input>
          </el-col>
        </el-row>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="isdfh = false" type="primary" size="small">取 消</el-button>
        <el-button @click="push_daifahuo_box" type="primary" size="small">确定</el-button>
      </span>
    </el-dialog>

    <el-dialog title="打印标签件数" :visible.sync="isbiaoqian" width="30%" @close="close_dialog_2">
      <div>
        <el-row style="display: flex; align-items: center">
          <el-col :span="5">标签标题 </el-col>
          <el-col :span="20">
            <el-input v-model="biaoqian_name" placeholder="请输入标签标题" style="width: 100%; text-align: left"></el-input>
          </el-col>
        </el-row>
        <el-row style="display: flex; align-items: center; margin-top: 10px">
          <el-col :span="5"> 件数 </el-col>
          <el-col :span="20">
            <el-input-number v-model="biaoqian_num" label="请输入件数" style="width: 100%; text-align: left"></el-input-number>
          </el-col>
        </el-row>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="isbiaoqian = false" type="primary" size="small">取 消</el-button>
        <el-button @click="prints_box" type="primary" size="small">确定</el-button>
      </span>
    </el-dialog>



    <el-dialog title="变更客户" :visible.sync="isbiao_kehu" width="30%" @close="close_dialog_2">
      <div>
        <el-row style="display: flex; align-items: center; margin-top: 10px">
          <el-col :span="5"> 订单号 </el-col>
          <el-col :span="20">
            <el-input v-model="obj_kehu.order_number" disabled style="width: 100%; text-align: left"></el-input>
          </el-col>
        </el-row>
        <el-row style="display: flex; align-items: center; margin-top: 10px">
          <el-col :span="5"> 客户 </el-col>
          <el-col :span="20">
            <el-select v-model="obj_kehu.customer_id" filterable placeholder="请选择客户" clearable style="width: 100%">
                <el-option v-for="(item, index) in CustomerList" :key="index" :label="item.customer_name"
                  :value="item.id">
                </el-option>
              </el-select>
          </el-col>
        </el-row>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="isbiao_kehu = false" type="primary" size="small">取 消</el-button>
        <el-button @click="push_kehu" type="primary" size="small">确定</el-button>
      </span>
    </el-dialog>






  </div>
</template>

<script>
import {
  getFinishProductList,
  getStockAllocationList,
  stockAllocation,
  setDeliveryStatus,
  setStockUpStatus,
  deductMoney,
  getCustomerList,
  getModelNumberList,
  getProductList,
  updateFinishProductNum,
  delFinishProduct,
  getStockAllocationLog,
  getFinishProductList_exports,
  cancelDelivery,
  setIsResidualPayment,
  editFinishProductCustomer
} from "@/api/product/index";
export default {
  inject: ["refresh"],
  data() {
    return {
      maxnum: 0,
      loading: true,
      isbiaoqian: false,
      biaoqian_name: "",
      biaoqian_num: "",
      disableds: {},
      logistics_statuslist: [
        {
          status: 1,
          lable: "待发货",
        },
        {
          status: 2,
          lable: "未发货",
        },
        // {
        //   status: 4,
        //   lable: "部分待发货",
        // },
        // {
        //   status: 5,
        //   lable: "部分未发货",
        // },
      ],
      rows: {},
      isdfh: false,
      remark: "",
      fahuo_num: "",
      // 搜索
      ModelNumberLists: [],
      ModelNumberList: [],
      order_data: [],
      ser: {
        serial_number: "",
        logistics_status: "",
        model_number_id: "",
        order_number: "",
        customer_id: "",
        product_id: "",
        order_date: "",
        is_replenishment: "",
        is_stock_up: "",
        start_time: "",
        end_time: "",
        is_residual_payment: '',
        order_type: "finish_product"
      },
      CustomerList: [],
      productList: [],

      isdayin: false,
      isjilu: false,
      ishuojia: false,
      dataList: [],
      pagination: {
        per_page:20,
        page: 1,
      },
      obj_kehu:{
        order_number:"",
        customer_id:"",
        finish_id:""
      },
      total: 0,
      dayinlist: [],
      dayinlist_biaoqian: [],
      diaoList: [],
      finish_product_id: "",
      diaohuojilulist: [],
      datalists: [],
      pagination_diao: {
        per_page: 5,
        page: 1,
      },
      total_diao: 0,
      isbiao_kehu:false
    };
  },
  mounted() {
    this.getlist();
    this.getproduct();
    this.getModel();
    this.getCustomer();
  },
  methods: {
    set_kehu(row){
      this.obj_kehu.order_number=row.order.order_number
      this.obj_kehu.finish_id=row.id
       this.getCustomer();
       this.isbiao_kehu=true
    },
    push_kehu(){
      if(this.obj_kehu.customer_id==''){
        this.$message({
            type: "error",
            message: "请选择客户",
          });
          return false;
      }
      editFinishProductCustomer(this.obj_kehu).then(res => {
        if (res.code == 200) {
          this.$message.success("操作成功~");
          this.getlist();
        }
      })
    },
    set_yishou(id) {
      let obj = {
        is_residual_payment: 1,
        order_id: id
      }
      setIsResidualPayment(obj).then(res => {
        if (res.code == 200) {
          this.$message.success("操作成功~");
          this.getlist();
        }
      })
    },
    set_cangku(row) {

    },
    push_daifahuos_false(row) {
      cancelDelivery({ order_id: row.order_id }).then(res => {
        if (res.code == 200) {
          this.$message.success("操作成功~");
          this.getlist();
        }
      })
    },
    del_FinishProduct(id) {
      delFinishProduct({ finish_product_id: id }).then((res) => {
        if (res.code == 200) {
          this.$message.success("操作成功~");
          this.getlist();
        }
      });
    },
    chengpin_shanchu(id, num) {
      this.$confirm("您确定删除订单号为：" + num + "的订单吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.del_FinishProduct(id);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    push_num_jianshu(id, num) {
      let obj = {
        id,
        num,
      };
      updateFinishProductNum(obj).then((res) => {
        if (res.code == 200) {
          this.$message.success("操作成功~");
          this.disableds["disableds_" + id] = true;
        }
      });
      this.getlist();
    },
    dbclick_input(id) {
      console.log("222", id);
      this.$nextTick(() => {
        this.disableds["disableds_" + id] = false;
        this.$forceUpdate();
      });
    },
    koukuan(id, type) {
      let obj = {
        finish_product_id: id,
        is_deduct_money: type,
      };
      deductMoney(obj)
        .then((res) => {
          if (res.code == 200) {
            this.$message.success("操作成功~");
            this.getlist();
          }
        })
        .catch((e) => {
          console.error(e);
        });
    },
    handleChange(val) {
      let num = this.rows.num - this.rows.to_be_sent_num;
      if (val == num) {
        this.fahuo_num = num - 1;
      }
    },
    // 指定查询
    search(type) {
      if (type == 0) {
        this.pagination.per_page = 10;
        this.pagination.page = 1;
      }
      getFinishProductList({ ...this.ser, ...this.pagination }).then((res) => {
        if (res.code == 200) {
          this.dataList = res.data.data;
          this.total = res.data.total;
          if (type == 2) {
            if (res.data.data.length > 0) {
              this.$message.success("正在导出订单列表");
              this.exports_w();
            }
          }
        }
      });
    },
    // 导出
    exports_w() {
      let data = {
        ...this.ser,
        export: 1,
      };
      getFinishProductList_exports(data).then((res) => {
        //创建一个隐藏的a连接，
        const link = document.createElement("a");
        let blob = new Blob([res.data], { type: "application/vnd.ms-excel" });
        link.style.display = "none";
        //设置连接
        link.href = URL.createObjectURL(blob);
        link.download = "成品库";
        document.body.appendChild(link);
        //模拟点击事件
        link.click();
      });
    },
    searchreset() {
      this.ser = {
        model_number_id: "",
        order_number: "",
        customer_id: "",
        product_id: "",
        order_date: "",
        is_replenishment: "",
        is_stock_up: "",
        start_time: "",
        end_time: "",
      };
      this.getlist();
    },
    //客户列表
    getCustomer() {
      getCustomerList().then((res) => {
        if (res.code == 200) {
          this.CustomerList = res.data.data;
        }
      });
    },
    //产品列表
    getproduct() {
      getProductList().then((res) => {
        if (res.code == 200) {
          this.productList = res.data.data;
        }
      });
    },
    // 型号列表
    getModel() {
      getModelNumberList().then((res) => {
        if (res.code == 200) {
          this.ModelNumberLists = res.data.data;
        }
      });
    },
    order_data_change(val) {
      this.ser.start_time = val[0];
      this.ser.end_time = val[1];
    },
    product_id_change(val) {
      console.log(val);
      this.ser.model_number_id = "";
      this.get_producModel(val)
    },
    get_producModel(id) {
      getModelNumberList({ product_id: id, field_list: 'id,model_number', is_dropdown: 1 }).then((res) => {
        if (res.code == 200) {
          this.ModelNumberList = res.data.data;
        }
      });
    },
    beihuo(row) {
      setStockUpStatus({
        id: row.id,
        order_id: row.order_id,
        is_stock_up: 1,
      }).then((res) => {
        if (res.code == 200) {
          this.$message({
            type: "success",
            message: "操作成功",
          });
          this.getlist();
        }
      });
    },
    push_daifahuos(row) {
      // if (row.models_field.is_residual_payment.key == 2) {
      //   this.$message.error('此订单未收余款，不能设为待发货！');
      //   return false
      // }
      this.$confirm('是否将此订单设置为待发货状态?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let ids = [];
        ids.push(row.id);
        let obj = {
          ids,
          num: row.num,
          remark: '',
        };
        setDeliveryStatus(obj).then((res) => {
          if (res.code == 200) {
            this.$message({
              type: "success",
              message: "操作成功",
            });
            this.getlist();
          }
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });





      // this.isdfh = true;
      // this.rows = row;
      // this.fahuo_num = row.num - row.to_be_sent_num - row.sent_num;
      // this.maxnum=(row.num-row.sent_num-row.to_be_sent_num)
    },
    // 弹框确认
    push_daifahuo_box() {
      if (this.fahuo_num == "") {
        this.$message.error("请输入数量");
        return false;
      }
      let ids = [];
      if (this.rows) {
        ids.push(this.rows.id);
      }
      let obj = {
        ids,
        num: this.fahuo_num,
        remark: this.remark,
      };

      setDeliveryStatus(obj).then((res) => {
        if (res.code == 200) {
          this.$message({
            type: "success",
            message: "操作成功",
          });
          this.isdfh = false;
          this.fahuo_num = "";
          this.remark = "";
          this.rows = {};
          this.getlist();
        }
      });
    },
    // 批量
    push_daifahuo() {
      let ids = [];
      if (this.dayinlist.length > 0) {
        this.dayinlist.forEach((item) => {
          ids.push(item.id);
        });
      } else {
        this.$message({
          type: "error",
          message: "请勾选数据",
        });
        return false;
      }

      setDeliveryStatus({ ids }).then((res) => {
        if (res.code == 200) {
          this.$message({
            type: "success",
            message: "操作成功",
          });
          this.getlist();
        }
      });
    },
    diaohuojilu(row) {
      this.isjilu = true;
      getStockAllocationLog({ finish_product_id: row.id }).then((res) => {
        if (res.code == 200) {
          this.diaohuojilulist = res.data;
        }
      });
    },
    close_dialog_2() {
      this.rows = {};
      this.fahuo_num = "";
    },
    close_dialog() {
      this.finish_product_id = "";
      this.diaohuojilulist = [];
    },
    //调货确认
    add_product(row) {
      stockAllocation({
        order_id: row.id,
        finish_product_id: this.finish_product_id,
      }).then((res) => {
        if (res.code == 200) {
          this.$message({
            type: "success",
            message: "操作成功",
          });
          this.getlist();
          this.ishuojia = false;
        }
      });
    },
    diaohuo(row) {
      if (row) {
        this.finish_product_id = row.id;
      }
      getStockAllocationList({ id: this.finish_product_id, ...this.pagination_diao }).then((res) => {
        if (res.code == 200) {
          if (res.data.data.length > 0) {
            this.ishuojia = true;
            this.diaoList = res.data.data;
            this.total_diao = res.data.total;
          } else {
            this.$message({
              type: "error",
              message: "暂无可调货订单",
            });
          }
        }
      });
    },
    // 获取成品库列表
    getlist() {
      getFinishProductList({
        ...this.pagination,
        ...this.ser
      }).then((res) => {
        if (res.code == 200) {
          this.dataList = res.data.data;
          this.dataList.forEach((item) => {
            const ob = "disableds_" + item.id;
            this.$set(this.disableds, ob, true);
          });
          this.total = res.data.total;
          this.loading = false;
        }
      });
    },
    handleSelectionChange(val) {
      this.dayinlist = val;
      this.dayinlist_biaoqian = val;
    },
    //打印出货单
    print() {
      if (this.dayinlist.length > 0) {
        const routerurl = this.$router.resolve({
          name: "dayin",
          path: "/dayin",
          query: {
            data: JSON.stringify(this.dayinlist),
          },
        });
        window.open(routerurl.href, "_blank");
      } else {
        this.$message({
          type: "error",
          message: "请勾选数据",
        });
        return false;
      }
    },
    push_num_jianshus(id, num) {
      let obj = {
        id,
        num,
      };
      updateFinishProductNum(obj).then((res) => {
        if (res.code == 200) {
          this.$message.success("操作成功~");
          this.isbiaoqian = false;
          this.dayinlist_biaoqian[0].num = this.biaoqian_num;
          this.dayinlist_biaoqian[0].biaoqian_name = this.biaoqian_name;
          const routerurl = this.$router.resolve({
            name: "biaoqian_mxs",
            path: "/biaoqian_mxs",
            query: {
              data: JSON.stringify(this.dayinlist_biaoqian),
            },
          });
          window.open(routerurl.href, "_blank");
          this.biaoqian_num = "";
          this.biaoqian_name = "";
          this.refresh();
        }
      });
    },
    //打印标签
    prints_box() {
      this.push_num_jianshus(this.dayinlist_biaoqian[0].id, this.biaoqian_num);
    },
    prints() {
      if (this.dayinlist_biaoqian.length == 1) {
        this.biaoqian_num = this.dayinlist_biaoqian[0].num;
        this.dayinlist_biaoqian[0].biaoqian_name = "";
        this.isbiaoqian = true;
      } else {
        if (this.dayinlist_biaoqian.length == 0) {
          this.$message({
            type: "error",
            message: "请勾选数据",
          });
          return false;
        }
        if (this.dayinlist_biaoqian.length > 1) {
          this.$message({
            type: "error",
            message: "只能选择一条数据",
          });
          return false;
        }
      }
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
       this.pagination.per_page=val
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.pagination.page = val;
      this.getlist();
    },
    prev() {
      this.pagination.page = this.pagination.page - 1;
      this.getlist();
    },
    next() {
      this.pagination.page = this.pagination.page + 1;
      this.getlist();
    },
    handleSizeChange_diao(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange_diao(val) {
      console.log(`当前页: ${val}`);
      this.pagination.page = val;
      this.diaohuo();
    },
    prev_diao() {
      this.pagination_diao.page = this.pagination_diao.page - 1;
      this.diaohuo();
    },
    next_diao() {
      this.pagination_diao.page = this.pagination_diao.page + 1;
      this.diaohuo();
    },
  },
};
</script>

<style scoped>
.el-dropdown-menu {
  text-align: center;
}

.el-dropdown-menu .el-button--text {
  width: 100%;
}
</style>
